/**
 * 
 */
package com.db.stockexchange.server.orderbook;

import com.db.stockexchange.common.OrderSide;

/**
 * @author Rayman
 * Represents deal between ask and bid orders
 */
public class Deal {
	private Order askOrder;
	private Order bidOrder;
	private Price price;
	private int quantity;

	public Deal(Order order1, Order order2, Price price, int quantity) {
		if (order1.getSide() == order2.getSide())
			throw new IllegalArgumentException("Order must have different types");
		
		if (order1.getSide() == OrderSide.BUY) {
			this.askOrder = order1;
			this.bidOrder = order2;
		}
		else {
			this.askOrder = order2;
			this.bidOrder = order1;
		}			
		
		this.price = price;
		this.quantity = quantity;
	}
	
	public Order getAskOrder() {
		return askOrder;
	}

	public Order getBidOrder() {
		return bidOrder;
	}

	public Price getPrice() {
		return price;
	}	
	
	public int getQuantity() {
		return quantity;
	}	
	
	@Override
	public String toString() {
		return "Deal: [" + askOrder.toString() + "]-[" + bidOrder.toString() + "], price=" + price.getValue() + ", quantity=" + quantity; 
	}
}
